class Solution {
    public:
        int rob(vector<int>& nums) {
            int size=nums.size();
            if(size==1){
                return nums[0];
            }
            int first=nums[0];
            int second=max(nums[0],nums[1]);
            for(int i=2;i<nums.size();i++){
                int temp=second;
                second = max(first + nums[i], second);
                first = temp;
            }
            return second;
        }
    };